package com.red.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.red.entity.Provider;
import com.red.result.Result;
import com.red.service.ProviderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/provider")
public class ProviderController {
    @Autowired
    private ProviderService providerService;

    @ApiOperation("根据条件查询供应商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "供应商名称"),
            @ApiImplicitParam(name = "number",value = "供应商编号")
    })
    @GetMapping("/select")
    public Result findAll(String name,String number){
        return new Result(
                providerService.list(
                        new QueryWrapper<Provider>()
                                .like(name!=null,"name",name)
                                .eq(number!=null,"number",number)
                )
        );
    }

    @ApiOperation("添加供应商")
    @PostMapping("/save")
    public Result save(Provider provider){
        return new Result(providerService.save(provider));
    }

    @ApiOperation("修改供应商")
    @PutMapping("/update")
    public Result update(Provider provider){
        return new Result(providerService.updateById(provider));
    }

    @ApiOperation("删除供应商")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        return  new Result(providerService.removeById(id));
    }
}
